package svc

import (
	dialogmodel "paper-pro/app/chat/model/chatdialog"
	msgmodel "paper-pro/app/chat/model/chatmsg"
	"paper-pro/app/chat/rpc/internal/config"
	assistantclient "paper-pro/pkg/rpc/assistant"

	"github.com/zeromicro/go-queue/dq"
	"github.com/zeromicro/go-zero/core/stores/redis"
	"github.com/zeromicro/go-zero/zrpc"
)

const (
	ChatDbName           = "chat"
	DialogCollectionName = "chat_dialogs"
	MsgCollectionName    = "chat_msgs"
)

type ServiceContext struct {
	Config config.Config

	RedisClient     *redis.Redis
	ChatDialogModel dialogmodel.ChatDialogModel
	ChatMsgModel    msgmodel.ChatMsgModel
	AssistantRpc    assistantclient.Assistant
	DqPusherClient  dq.Producer
}

func NewServiceContext(c config.Config) *ServiceContext {
	return &ServiceContext{
		Config: c,

		RedisClient:     redis.MustNewRedis(c.RedisConf),
		ChatDialogModel: dialogmodel.NewChatDialogModel(c.MongoDB.Source, ChatDbName, DialogCollectionName, c.Cache),
		ChatMsgModel:    msgmodel.NewChatMsgModel(c.MongoDB.Source, ChatDbName, MsgCollectionName),
		AssistantRpc:    assistantclient.NewAssistant(zrpc.MustNewClient(c.AssistantRpcConf)),
		DqPusherClient:  dq.NewProducer(c.DqConf),
	}
}
